package com.biz.primus.ms.order.api;

import com.biz.primus.model.order.vo.aftersale.*;
import com.biz.primus.model.order.vo.request.OrderCodeVO;
import com.biz.primus.ms.base.api.BaseApiController;
import com.biz.primus.ms.order.service.ReturnOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 退货单控制器
 *
 * @author Tiger Feng
 * @date 2017年11月20日
 */
@RestController
@RequestMapping("soa/orderService/returnOrder")
@Api("退货单相关接口文档")
public class ReturnOrderApiController extends BaseApiController {
    @Autowired
    private ReturnOrderService returnOrderService;

    @ApiOperation(value = "查询订单信息以用于售后服务", notes = "根据订单编码获取订单信息，以便用于售后界面展示")
    @GetMapping("queryByOrderCode4AfterSale")
    public QueryOrderResponseVO queryByOrderCode4AfterSale(
            @RequestBody OrderCodeVO orderCodeVO) {
        return returnOrderService.getByOrderCode4AfterSale(orderCodeVO.getOrderCode());
    }

    @ApiOperation(value = "申请退货单", notes = "申请创建退货单")
    @PostMapping("applyReturnOrder")
    public ReturnOrderResponseVO applyReturnOrder(
            @RequestBody ReturnOrderRequestVO returnOrderRequestVO) {
        return returnOrderService.applyReturnOrder(returnOrderRequestVO);
    }

    @ApiOperation(value = "查询退货单", notes = "根据订单编码获取退货单，当前订单的退货单，一个订单只能有一个退货单")
    @GetMapping("queryByOrderCode")
    public ReturnOrderResponseVO queryByOrderCode(
            @RequestBody OrderCodeVO orderCodeVO) {
        return returnOrderService.getByOrderCode(orderCodeVO.getOrderCode());
    }

    @ApiOperation(value = "补充退货单物流信息", notes = "用户将退货商品回寄的物流单号、物流名称等信息补充到退货单中")
    @PostMapping("addLogisticsInfo")
    public ReturnOrderResponseVO addLogisticsInfo(
            @RequestBody ReturnOrderAddLogisticsRequestVO returnOrderAddLogisticsRequestVO) {
        return returnOrderService.addLogisticsInfo(returnOrderAddLogisticsRequestVO);
    }

    @ApiOperation(value = "取消退货单", notes = "用户取消退货单，需要传入退货单,成功返回true")
    @PostMapping("cancelReturnOrder")
    public Boolean cancelReturnOrder(
            @RequestBody ReturnCodeVO returnCodeVO) {
        return returnOrderService.cancelReturnOrder(returnCodeVO.getReturnCode());
    }


}
